/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import entidad.reporte;
import java.util.ArrayList;

/**
 *
 * @author Stiv
 */
public class algoritmoSMA {


    public double calc_error(reporte Ft, reporte At,int n){
        double error=0;
        ArrayList<Double> ft = Ft.getReportes();
        ArrayList<Double> at = At.getReportes();
        double aux=0;
        for(int i=0;i<n;i++){
            aux=aux+(at.get(i)-ft.get(i))/at.get(i);
        }
        error=1/n*aux;
        return error;
    }
    
    //Movil Simple
    public ArrayList MMS (reporte A,int z){
        
        ArrayList<Double> a= A.getReportes();
        ArrayList<Double> b= new ArrayList();
        int m=z;
        Double MMS;
        
        while(m!=0){
        Double s=0.0;
        int n = a.size();
        for(int i=0; i<n;i++){
        s=s+a.get(i);}
        MMS=s/n;
        a.add(MMS);
        b.add(MMS);
        m--;
        }
        
        return b;
    }
    //Movil Doble
    public ArrayList MMD (reporte A,int z){
    
       Double Mp;
       ArrayList<Double> b= MMS(A,z);
       ArrayList<Double> c = new ArrayList();
       ArrayList<Double> d = new ArrayList();
       int m=z;
       int n = b.size();
       
       for(int i=0;i<n;i++){
        Double s=0.0;
        for(int j=0; j<i;j++){
        s=s+b.get(j);}
        Mp=s/n;
        c.add(Mp);
        }
       
       for(int i=0;i<n;i++){
           Double a=2*b.get(i)-c.get(i);
           Double b1=(2*b.get(i)-c.get(i))/(i+1);
           d.add(a*b1*(i+1));
       }     
       
    return d;
    }
    //Ajuste Exponencial Simple
    public ArrayList AExpSimple (reporte A, int z){
        
        ArrayList<Double> a = MMS(A,z);
        ArrayList<Double> b = new ArrayList();
                
        b.add(a.get(0));
        
        for(int i=1;i==a.size()-1;i++){
        
            Double p=0.7*b.get(i-1)+0.3*a.get(i-1);
            b.add(p);
        }
        return b;
    }
    // ajuste exponencial Doble
    public ArrayList AExpDoble (reporte A, int z){
        
        ArrayList<Double> a = AExpSimple(A,z);
        ArrayList<Double> b = new ArrayList();
        ArrayList<Double> c = new ArrayList();
        b.add(a.get(0));
        
        for(int i=1;i==a.size()-1;i++){
        
            Double p=0.7*b.get(i-1)+0.3*a.get(i-1);
            b.add(p);
        }
        
        for(int i=0;i==z-1;i++){
        
            Double a1=2*a.get(i)-b.get(i);
            Double b1=a1*(a.get(i)-b.get(i))/(1-a1);
            c.add(a1+b1*(i+1));
        }
        
        return c;
    }
}
